package com.atguigu.flink.chapter11;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

/**
 * @Author lzc
 * @Date 2022/10/31 10:41
 */
public class Flink08_SQL_UpsertKafka_2 {
    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();
        conf.setInteger("rest.port", 2002);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
        env.setParallelism(2);
        
        StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
        
        // 建立一张表与kafka 的 topic 关联: ddl(建表语句)
        tEnv.executeSql("create table sa(" +
                            "id string, " +
                            "vc_sum int, " +
                            "primary key(id) not enforced " +
                            ")with(" +
                            "  'connector' = 'upsert-kafka', " +
                            "  'topic' = 'sa', " +
                            "  'properties.bootstrap.servers' = 'hadoop162:9092', " +
                            "  'key.format' = 'json'," +
                            "  'value.format' = 'json'" +
                            ")");
        
       tEnv.sqlQuery("select * from sa").execute().print();
    
        
        
    }
}
/*
普通的 kafka 连接器只支持写入 append only 数据, 不能写入更新数据

 */